home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / MoreFiles 1.1.1 / DirectoryCopy.p < prev    next >
Encoding:
Text File  |  1994-01-18  |  6.9 KB  |  164 lines  |  [TEXT/PJMM]

  1. UNIT DirectoryCopy;
  2.  
  3.  
  4. {    Apple Macintosh Developer Technical Support                                }
  5. {                                                                            }
  6. {    DirectoryCopy: A robust, general purpose directory copy routine.        }
  7. {    by Jim Luther, Apple Developer Technical Support                        }
  8. {                                                                            }
  9. {    File:        DirectoryCopy.p                                                }
  10. {                                                                            }
  11. {    Copyright © 1992-1994 Apple Computer, Inc.                                }
  12. {    All rights reserved.                                                    }
  13. {                                                                            }
  14. {    You may incorporate this sample code into your applications without        }
  15. {    restriction, though the sample code has been provided "AS IS" and the    }
  16. {    responsibility for its operation is 100% yours.  However, what you are    }
  17. {    not permitted to do is to redistribute the source as "DSC Sample Code"    }
  18. {    after having made changes. If you're going to re-distribute the source,    }
  19. {    we require that you make it clear in the source that the code was        }
  20. {    descended from Apple Sample Code, but that you've made changes.            }
  21.  
  22.  
  23. INTERFACE
  24.  
  25. {***************************************************************************}
  26.  
  27.     { DirectoryCopy failedOperation codes. }
  28.     CONST
  29.         getNextItemOp = 1;            { couldn't access items in this }
  30.                                     { directory - no access privileges }
  31.         copyDirCommentOp = 2;        { couldn't copy directory's Finder }
  32.                                     { comment }
  33.         copyDirAccessPrivsOp = 3;    { couldn't copy directory's AFP access }
  34.                                     { privileges }
  35.         copyDirFMAttributesOp = 4;    { couldn't copy directory's File }
  36.                                     { Manager attributes }
  37.         dirCreateOp = 5;            { couldn't create destination directory }
  38.         fileCopyOp = 6;                { couldn't copy file }
  39.  
  40.  
  41. {***************************************************************************}
  42.  
  43.     TYPE
  44.         CopyErrProcPtr = ProcPtr;
  45.  
  46. {    A DirectoryCopy CopyErrProc function should have the following form:    }
  47. {                                                                            }
  48. {    FUNCTION MyCopyErrProc (error: OSErr;                                     }
  49. {                            failedOperation: Integer;                        }
  50. {                            srcVRefNum: Integer;                            }
  51. {                            srcDirID: LongInt;                                }
  52. {                            srcName: StringPtr;                                }
  53. {                            dstVRefNum: Integer;                            }
  54. {                            dstDirID: LongInt;                                }
  55. {                            dstName: StringPtr): Boolean;                    }
  56. {                                                                            }
  57. {    DirectoryCopy will call your CopyErrProc function if an error condition    }
  58. {    is detected sometime during the copy.  If your CopyErrProc returns        }
  59. {    true, then DirectoryCopy attempts to continue with the directory copy    }
  60. {    operation.  If your CopyErrProc returns false, then DirectoryCopy stops    }
  61. {    the directory copy operation.                                            }
  62. {                                                                            }
  63. {    error            input:    The error result code that caused CopyErrProc    }
  64. {                            to be called.                                    }
  65. {    failedOperation    input:    The operation that returned an error to            }
  66. {                            DirectoryCopy.                                    }
  67. {    srcVRefNum        input:    Source volume specification.                    }
  68. {    srcDirID        input:    Source directory ID.                            }
  69. {    srcName            input:    Source file or directory name, or nil if        }
  70. {                            srcDirID specifies the directory.                }
  71. {    dstVRefNum        input:    Destination volume specification.                }
  72. {    dstDirID        input:    Destination directory ID.                        }
  73. {    dstName            input:    Destination file or directory name, or nil if    }
  74. {                            dstDirID specifies the directory.                }
  75.  
  76.  
  77. {***************************************************************************}
  78.  
  79.  
  80.     FUNCTION DirectoryCopy (srcVRefNum: Integer;
  81.                                     srcDirID: LongInt;
  82.                                     srcName: StringPtr;
  83.                                     dstVRefNum: Integer;
  84.                                     dstDirID: LongInt;
  85.                                     dstName: StringPtr;
  86.                                     copyBufferPtr: Ptr;
  87.                                     copyBufferSize: LongInt;
  88.                                     preflight: Boolean;
  89.                                     copyErrHandler: CopyErrProcPtr): OSErr;
  90. {    Use DirectoryCopy to make a copy of a directory structure in a new        }
  91. {    location.  If copyBufferPtr <> NIL, it points to a buffer of            }
  92. {    copyBufferSize that is used to copy files data.  The larger the            }
  93. {    supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then        }
  94. {    this routine allocates a buffer in the application heap. If you pass a    }
  95. {    copy buffer to this routine, make its size a multiple of 512            }
  96. {    ($200) bytes for optimum performance.                                    }
  97. {                                                                            }
  98. {    srcVRefNum        input:    Source volume specification.                    }
  99. {    srcDirID        input:    Source directory ID.                            }
  100. {    srcName            input:    Source directory name, or nil if                }
  101. {                            srcDirID specifies the directory.                }
  102. {    dstVRefNum        input:    Destination volume specification.                }
  103. {    dstDirID        input:    Destination directory ID.                        }
  104. {    dstName            input:    Destination directory name, or nil if            }
  105. {                            dstDirID specifies the directory.                }
  106. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  107. {                            is used the i/o buffer for the copy or            }
  108. {                            nil if you want DirectoryCopy to allocate its    }
  109. {                            own buffer in the application heap.                }
  110. {    copyBufferSize    input:    The size of the buffer pointed to                }
  111. {                            by copyBufferPtr.                                }
  112. {    preflight        input:    If true, DirectoryCopy makes sure there are        }
  113. {                            enough allocation blocks on the destination        }
  114. {                            volume to hold the directory's files before        }
  115. {                            starting the copy.                                }
  116. {    copyErrHandler    input:    A pointer to the routine you want called if an    }
  117. {                            error condition is detected during the copy, or    }
  118. {                            nil if you don't want to handle error            }
  119. {                            conditions. Error handling is recommended...    }
  120.  
  121.  
  122. {***************************************************************************}
  123.  
  124.  
  125.     FUNCTION FSpDirectoryCopy (srcSpec: FSSpec;
  126.                                     dstSpec: FSSpec;
  127.                                     copyBufferPtr: Ptr;
  128.                                     copyBufferSize: LongInt;
  129.                                     preflight: Boolean;
  130.                                     copyErrHandler: CopyErrProcPtr): OSErr;
  131. {    Use FSpDirectoryCopy to make a copy of a directory structure in a new    }
  132. {    location.  If copyBufferPtr <> NIL, it points to a buffer of            }
  133. {    copyBufferSize that is used to copy files data.  The larger the            }
  134. {    supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then        }
  135. {    this routine allocates a buffer in the application heap. If you pass a    }
  136. {    copy buffer to this routine, make its size a multiple of 512            }
  137. {    ($200) bytes for optimum performance.                                    }
  138. {                                                                            }
  139. {    srcSpec            input:    An FSSpec record specifying the directory to    }
  140. {                            copy.                                            }
  141. {    dstSpec            input:    An FSSpec record specifying destination            }
  142. {                            directory of the copy.                            }
  143. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  144. {                            is used the i/o buffer for the copy or            }
  145. {                            nil if you want DirectoryCopy to allocate its    }
  146. {                            own buffer in the application heap.                }
  147. {    copyBufferSize    input:    The size of the buffer pointed to                }
  148. {                            by copyBufferPtr.                                }
  149. {    preflight        input:    If true, FSpDirectoryCopy makes sure there are    }
  150. {                            enough allocation blocks on the destination        }
  151. {                            volume to hold the directory's files before        }
  152. {                            starting the copy.                                }
  153. {    copyErrHandler    input:    A pointer to the routine you want called if an    }
  154. {                            error condition is detected during the copy, or    }
  155. {                            nil if you don't want to handle error            }
  156. {                            conditions. Error handling is recommended...    }
  157.  
  158.  
  159. {***************************************************************************}
  160.  
  161.  
  162. IMPLEMENTATION
  163.  
  164. END.